/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author dchapman
 */
@Entity
@Table(name = "LabProcess")
@XmlRootElement
public class LabProcess implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "labProcessID")
    private Integer lpid;
    @Size(min = 0, max = 100)
    @Column(name = "labProcessDesc")
    private String lpdesc;
    @Basic(optional = false)
    @NotNull
    @Column(name = "taskMinutes")
    private int taskMinutes;
    @Basic(optional = false)
    @NotNull
    @Column(name = "taskMen")
    private int taskMen;
    @Basic(optional = false)
    @NotNull
    @Column(name = "rateType")
    private int rateType;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="JTLabProcessToDoc",
        joinColumns={ @JoinColumn(name="labProcessID", referencedColumnName="labProcessID")},
        inverseJoinColumns={ @JoinColumn(name="docID", referencedColumnName="docID", unique=true)}
    )
    private List<Documents> docCollection;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTLabProcessToInvUsage",
        joinColumns={ @JoinColumn(name="labProcessID", referencedColumnName="labProcessID")},
        inverseJoinColumns={ @JoinColumn(name="InvUsageID", referencedColumnName="InvUsageID", unique=true)}
    )
    private List<InventoryUsage> invUsageCollection;
    
    @OneToMany(mappedBy = "labProcess")
    private Collection<LabType> labTypeCollection;

    public LabProcess() {
    }

    public LabProcess(Integer lpid) {
        this.lpid = lpid;
    }

    public LabProcess(Integer lpid, String lpdesc) {
        this.lpid = lpid;
        this.lpdesc = lpdesc;
    }

    public Integer getLpid() {
        return lpid;
    }

    public void setLpid(Integer lpid) {
        this.lpid = lpid;
    }

    public String getLpdesc() {
        return lpdesc;
    }

    public void setLpdesc(String lpdesc) {
        this.lpdesc = lpdesc;
    }

    public List<Documents> getDocCollection() {
        return docCollection;
    }

    public void setDocCollection(List<Documents> docCollection) {
        this.docCollection = docCollection;
    }

    public List<InventoryUsage> getInvUsageCollection() {
        return invUsageCollection;
    }

    public void setInvUsageCollection(List<InventoryUsage> invUsageCollection) {
        this.invUsageCollection = invUsageCollection;
    }

    public int getTaskMinutes() {
        return taskMinutes;
    }

    public void setTaskMinutes(int taskMinutes) {
        this.taskMinutes = taskMinutes;
    }

    public int getTaskMen() {
        return taskMen;
    }

    public void setTaskMen(int taskMen) {
        this.taskMen = taskMen;
    }

    public int getRateType() {
        return rateType;
    }

    public void setRateType(int rateType) {
        this.rateType = rateType;
    }

    @XmlTransient
    public Collection<LabType> getLabTypeCollection() {
        return labTypeCollection;
    }

    public void setLabTypeCollection(Collection<LabType> labTypeCollection) {
        this.labTypeCollection = labTypeCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (lpid != null ? lpid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LabProcess)) {
            return false;
        }
        LabProcess other = (LabProcess) object;
        if ((this.lpid == null && other.lpid != null) || (this.lpid != null && !this.lpid.equals(other.lpid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.LabProcess[ lpid=" + lpid + " ]";
    }
}
